<?php
	
    class LogEngine
    {
		private $template;
		private $dbProvider;
		
		public function __construct()
        {
            $this->template = new TemplateEngine();
			$this->dbProvider = new UserDataProvider();
        }
		
		public function checkSet()
		{
			$isSet = isset( $_POST['email'] ) && isset( $_POST['password'] );
			if ( $isSet )
			{	
				return true;
			}
			else
			{
				throw new Exception( $this->template->convertToHtml( "Parametres from form not passed!" ) );
				return false;
			}
		}
		
		public function findInBase( $email, $password )
        {
			$isValid = ( !empty( $email ) && !empty( $password ) );
			if ( $isValid )
			{
				$email = strtolower( $email );
				if ( $this->dbProvider->checkLoginInDb( $email, $password ) )
				{
					return true;
				}
				else
				{
					throw new Exception( $this->template->convertToHtml( "This login is not exist!" ) );
					return false;
				}
			}
			else
			{
				throw new Exception( $this->template->convertToHtml( "Not all data is entered!" ) );
				return false;
			}
        }
		
		public function getNameByEmail( $email )
		{
			$email = strtolower( $email );
			$resultArr = $this->dbProvider->getUserDataFromDb( $email );
		   
			return $resultArr;
		}
	}

?>